home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
-
- proc int dynSettingsInList(string $list[], string $name)
- //
- // Return whether $name is in $list.
- //
- {
- int $inList = 0;
- for ($i = 0; $i < size($list); $i++)
- {
- if ($name == $list[$i])
- {
- $inList = 1;
- break;
- }
- }
- return $inList;
- }
-
- global proc cacheControl( int $flag )
- //
- // Enable the cache for all the selected dynamic objects.
- {
-
- // What's selected is probably a transform, so we probably have to find the particle,
- // rigid body shapes in the transforms.
- //
- // Get selected particles and rigid bodies if there are any.
- //
- string $selectedParticles[] = `ls -sl -type particle`;
- string $selectedRigidBodies[] = `ls -sl -type rigidBody`;
- string $selectedTransforms[] = `ls -sl -transforms`;
-
- // Get the particle shapes from all selected transforms that own
- // particle shapes.
- //
- for ($i = 0; $i < size($selectedTransforms); $i++)
- {
- string $kidShapes[] = `listRelatives -s $selectedTransforms[$i]`;
- string $particleKids[] = `ls -type particle $kidShapes`;
- int $particleCount = size($selectedParticles);
- for ($j = 0; $j < size($particleKids); $j++)
- {
- if (!dynSettingsInList($selectedParticles, $particleKids[$j]))
- {
- $selectedParticles[$particleCount] = $particleKids[$j];
- $particleCount++;
- }
- }
- }
-
- // Get the rigid body shapes from all selected transforms that own
- // rigid body shapes.
- //
- for ($i = 0; $i < size($selectedTransforms); $i++)
- {
- string $kidShapes[] = `listRelatives -s $selectedTransforms[$i]`;
- string $rigidBodyKids[] = `ls -type rigidBody $kidShapes`;
- int $rigidCount = size($selectedRigidBodies);
- for ($j = 0; $j < size($rigidBodyKids); $j++)
- {
- if (!dynSettingsInList($selectedRigidBodies, $rigidBodyKids[$j]))
- {
- $selectedRigidBodies[$rigidCount] = $rigidBodyKids[$j];
- $rigidCount++;
- }
- }
- }
-
- // Collect the list of unique rigid solvers related to the selected rigid
- // bodies and set the solver names in one string for the feedback line,
- // because the caching is done by the solver, rather than the rigid body.
- //
- string $rigidSolvers[];
- string $rigidSolver;
- string $rigidSolverNames;
- int $solverCount = 0;
-
- for ($i = 0; $i < size($selectedRigidBodies); $i++)
- {
- $rigidSolver = `rigidBody -q -solver $selectedRigidBodies[$i]`;
- if (!dynSettingsInList($rigidSolvers, $rigidSolver))
- {
- $rigidSolvers[$solverCount] = $rigidSolver;
- $rigidSolverNames = $rigidSolverNames + " " + $rigidSolver;
- $solverCount++;
- }
- }
-
- // Now set cache for each particle.
- //
- int $particleCount = size($selectedParticles);
-
- string $cmd = "particle -e -cache " + $flag;
- string $particleNames;
- for ($i = 0; $i < $particleCount; $i++)
- {
- $cmd = "particle -e -cache " + $flag + " " + $selectedParticles[$i];
- $particleNames = $particleNames + " " + $selectedParticles[$i];
- evalEcho $cmd;
-
- }
-
- // Give the user feedback.
- //
- if ($particleCount > 0)
- {
- if ( $flag )
- {
- print ( "// Result: Cache enabled for " + $particleNames + ".\n" );
- }
- else
- {
- print ( "// Result: Cache disabled for " + $particleNames + ".\n" );
- }
- }
-
-
- // Now set cache for each rigid solver.
- //
- $solverCount = size($rigidSolvers);
- for ($i = 0; $i < $solverCount; $i++)
- {
- $cmd = "rigidSolver -e -cacheData " + $flag + " " + $rigidSolvers[$i];
- evalEcho $cmd;
- }
-
- // Give the user feedback.
- //
- if ($solverCount > 0)
- {
- if ( $flag )
- {
- print ( "// Result: Cache enabled for all rigid bodies of: " + $rigidSolverNames + ".\n" );
- }
- else
- {
- print ( "// Result: Cache disabled for all rigid bodies of: " + $rigidSolverNames + ".\n" );
- }
- }
- }
-